package academic.emailClient.control.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import academic.emailClient.control.MessageMapper;
import academic.emailClient.model.EmailClientModel;
import academic.emailClient.model.entities.Message;
import academic.emailClient.view.EmailClientViewInterface;
import academic.emailClient.view.entities.MessageView;

public class SearchingTheMessageListener implements ActionListener{
	
	private EmailClientViewInterface view;	
	private EmailClientModel model;	
	private ArrayList<String> msgSearched;
	private ArrayList<Message> msg;
	
	/**
	 * Constructor
	 * @param view
	 */
	public SearchingTheMessageListener(EmailClientViewInterface view,EmailClientModel model){
		this.view = view;
		this.model=model;
	}
	

/**
 * This method is  used to tell how to react to the Search button action
 * by taking the values in the view and create a search query to fetch
 * the appropriate data and diplay them
 * 
 * @author 
 *
  */
	
	public void actionPerformed(ActionEvent evt) {
	    msgSearched=this.view.getSearchedMessage();
	    
	    msg=model.searchNewQuery(msgSearched);
		ArrayList<MessageView> messagesView =  MessageMapper.mapToMessageViewList(msg);
		view.updateMailBoxList(messagesView);
	  }                     
}
  



